<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css">
    <link rel="stylesheet" href="/lib/public.css" media="all">
</head>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="">
            <input TYPE="hidden" name="id" >
            <input TYPE="hidden" name="salt" >
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" required  lay-verify="required" placeholder="请输入类别名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" required   autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="newPassword" required   autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重复新密码</label>
                <div class="layui-input-block">
                    <input type="password" required   autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input type="text" name="phone"    autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email"    autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="realname"    autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>

<script src="/lib/layui-v2.6.3/layui.js"></script>
<script>
    //Demo
    layui.use(['form','laytpl','upload', 'element', 'layer'], function(){
        var form = layui.form,
            $=layui.$,
            laytpl=layui.laytpl,
            upload = layui.upload,
            element = layui.element,
            layer = layui.layer;

        $.ajax({
            url:`/api/admin/info`,
            type:"GET",
            dataType:"JSON",
            success:function (resp) {
               /* layer.msg(resp);*/
                console.log(resp);
                let data = resp.data;
                $("input[name='id']").val(data.id);
                $("input[name='salt']").val(data.salt);
                $("input[name='username']").val(data.username);
                $("input[name='phone']").val(data.phone);
                $("input[name='email']").val(data.email);
                $("input[name='realname']").val(data.realname);
                form.render();
            }
        })


        //提交
        form.on('submit(formDemo)', function(data){
            console.log(data.field);
            $.ajax({
                url:"/api/admin",
                type: "PUT",
                data: JSON.stringify(data.field),
                contentType:"application/json;charset=UTF-8",
                dataType: "JSON",
                success: function (resp){
                    layer.msg(resp.msg,{time: 1000},function (){
                        if (resp.code === 10000){
                            parent.layer.closeAll("iframe");
                        }
                    })

                }
            })
            return false;
        });

        form.render();
    });
</script>
</body>
</html>